<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
</head>
<body>
    <div class="main-content">
        <tags:breadcrumb menuId="9c62e0709a93477d81224b44893c305a" />
        <div class="page-content">
                <form:form id="inputForm" modelAttribute="user" action="${ctx}/sys/user/save" method="post" class="form-horizontal">
                <form:hidden path="id"/>
                <div class="form-group">
                    <label class="col-sm-2 no-padding-right control-label">归属公司:</label>
                    <div class="col-sm-4">
                        <tags:treeselect id="company" name="company.id" value="${user.company.id}" labelName="company.name" labelValue="${user.company.name}"
                                         title="公司" url="/sys/office/treeData?type=1" selectIds="${user.company.id}" cssClass="required col-sm-9"/>
                    </div>
                    <label class="col-sm-2 no-padding-right control-label">登录名:</label>
                    <div class="col-sm-4">
                        <input id="oldLoginName" name="oldLoginName" type="hidden" value="${user.loginName}">
                        <form:input path="loginName" htmlEscape="false" maxlength="50" class="required userName col-sm-10"/>
                    </div>
                </div><hr/>
                <div class="form-group">
                    <label class="col-sm-2 no-padding-right control-label">工号:</label>
                    <div class="col-sm-4">
                        <form:input path="cardNo" htmlEscape="false" maxlength="50" class="required col-sm-10"/>
                    </div>
                    <label class="col-sm-2 no-padding-right control-label">姓名:</label>
                    <div class="col-sm-4">
                        <form:input path="name" htmlEscape="false" maxlength="50" class="required col-sm-10"/>
                    </div>
                </div><hr/>
                <div class="form-group">
                    <label class="col-sm-2 no-padding-right control-label">密码:</label>
                    <div class="col-sm-4">
                        <input id="newPassword" name="newPassword" type="password" value="" maxlength="50" minlength="3" class="${empty user.id?'required':''} col-sm-10"/>
                        <c:if test="${not empty user.id}"><span class="help-inline">若不修改密码，请留空。</span></c:if>
                    </div>
                    <label class="col-sm-2 no-padding-right control-label">确认密码:</label>
                    <div class="col-sm-4">
                        <input id="confirmNewPassword" name="confirmNewPassword" type="password" value="" maxlength="50" minlength="3" equalTo="#newPassword" class="col-sm-10"/>
                    </div>
                </div><hr />
                <div class="form-group">
                    <label class="col-sm-2 no-padding-right control-label">邮箱:</label>
                    <div class="col-sm-4">
                        <form:input path="email" htmlEscape="false" maxlength="100" class="email col-sm-10"/>
                    </div>
                    <label class="col-sm-2 no-padding-right control-label">电话:</label>
                    <div class="col-sm-4">
                        <form:input path="phone" htmlEscape="false" maxlength="100" cssClass="col-sm-10"/>
                    </div>
                </div><hr />
                <div class="form-group">
                    <label class="col-sm-2 no-padding-right control-label">手机:</label>
                    <div class="col-sm-4">
                        <form:input path="mobile" htmlEscape="false" maxlength="100" cssClass="col-sm-10"/>
                    </div>
                    <label class="col-sm-2 no-padding-right control-label">用户类型:</label>
                    <div class="col-sm-4">
                        <form:select path="userType" cssClass="col-sm-10">
                            <form:option value="" label="请选择"/>
                            <form:options items="${fns:getDictList('sys_user_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                        </form:select>
                    </div>
                </div><hr />
                <div class="form-group">
                    <label class="col-sm-2 no-padding-right control-label">用户角色:</label>
                    <div class="col-sm-8" style="margin-top: 8px;">
                        <form:checkboxes path="roleIdList" items="${allRoles}" itemLabel="name" itemValue="id" htmlEscape="false" class="required"/>
                    </div>
                </div><hr/>
                <div class="form-group">
                    <label class="col-sm-2 no-padding-right control-label">备注:</label>
                    <div class="col-sm-4">
                        <form:textarea path="remarks" htmlEscape="false" rows="2" maxlength="200" cssStyle="width:600px;"/>
                    </div>
                </div>
                <c:if test="${not empty user.id}">
                    <div class="row-fluid">
                        <div class="control-group">
                            <div class="span6">
                                <label class="control-label">创建时间:</label>
                                <div class="controls">
                                    <label class="lbl"><fmt:formatDate value="${user.createDate}" type="both" dateStyle="full"/></label>
                                </div>
                            </div>
                            <div class="span6">
                                <label class="control-label">最后登陆:</label>
                                <div class="controls">
                                    <label class="lbl">IP: ${user.loginIp}&nbsp;&nbsp;&nbsp;&nbsp;时间：<fmt:formatDate value="${user.loginDate}" type="both" dateStyle="full"/></label>
                                </div>
                            </div>
                        </div>
                    </div>
                </c:if>
                <div class="form-actions">
                    <div class="col-md-offset-2">
                        <shiro:hasPermission name="sys:user:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
                        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
                    </div>
                </div>
            </div>
            </form:form>
    </div>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#loginName").focus();
			$("#inputForm").validate({
				rules: {
					loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${user.loginName}')}
				},
				messages: {
					loginName: {remote: "用户登录名已存在"},
					confirmNewPassword: {equalTo: "输入与上面相同的密码"}
				},
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
</body>
</html>